package com.vast.ui.component.providers;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Item;

import socketinterface.CommunicationManager;

import com.vast.ui.component.models.Io;

public class IoModifier implements ICellModifier {
	private TableViewer viewer;
	
	
	public IoModifier (TableViewer viewer) {
		this.viewer = viewer;
		
	}
	
	public boolean canModify(Object element, String property) {
		// TODO Auto-generated method stub
		return true;
	}

	public Object getValue(Object element, String property) {
		// TODO Auto-generated method stub
		if (element instanceof Io) {
			Io io = (Io) element;
			if (property.equals("0")) {
				return io.isChecked(0);
			} else if (property.equals("1")) {
				return io.isChecked(1);
			} else if (property.equals("2")) {
				return io.isChecked(2);
			} else if (property.equals("3")) {
				return io.isChecked(3);
			} else if (property.equals("4")) {
				return io.isChecked(4);
			} else if (property.equals("5")) {
				return io.isChecked(5);
			} else if (property.equals("6")) {
				return io.isChecked(6);
			}
		}
		return null;
	}

	public void modify(Object element, String property, Object value) {
		// TODO Auto-generated method stub
		if (element instanceof Item) {
			Object item = ((Item) element).getData();
			Io io = (Io) item;			
			if (property.equals("0")) {
				io.setChecked(0, ((Boolean) value).booleanValue());
			} else if (property.equals("1")) {
				io.setChecked(1, ((Boolean) value).booleanValue());
			} else if (property.equals("2")) {
				io.setChecked(2, ((Boolean) value).booleanValue());
			} else if (property.equals("3")) {
				io.setChecked(3, ((Boolean) value).booleanValue());
			} else if (property.equals("4")) {
				io.setChecked(4, ((Boolean) value).booleanValue());
			} else if (property.equals("5")) {
				io.setChecked(5, ((Boolean) value).booleanValue());
			}
			viewer.update(io, null);
		}
	}

}
